package com.yunbao.hujin.zqqgetuidemo.framenttoactivity;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

import com.yunbao.hujin.zqqgetuidemo.R;

/**
 * fragment需要传给Activity值
 */
public class BlankFragment extends Fragment {

    private EditText etInput;
    private Button btn;
    private CallBack callBack;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        callBack = (CallBack) getActivity();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_blank, container, false);
        etInput = view.findViewById(R.id.etInput);
        btn = view.findViewById(R.id.btn);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String content = etInput.getText().toString().trim();
                if (null != content && !"".equals(content)) {
                    callBack.putStringValue(content);
                } else {
                    Snackbar.make(btn, "请输入值", Snackbar.LENGTH_SHORT).show();
                }
            }
        });
    }
}
